module.exports = function ($scope, $resource, $modal, toaster) {

	//查询产品列表
	$scope.getList = function() {
		$resource('/api/as/tc/grouporder/groupsalelist', {}, {}).save($scope.searchParams, function (res) {
            if (res.errcode === 0) {
				$scope.viewMap = {};
				res.data.forEach(function(value, index){
					if (!$scope.viewMap.hasOwnProperty(value.place_code)){
						$scope.viewMap[value.place_code] = {
							'sale_name': value.place_name,
							'img': value.img || 'http://shangke2.oss-cn-qingdao.aliyuncs.com/app/aa/bb/none.jpg',
							'place_name': value.place_name,
							'company_name': value.company_name,
							'address': value.address,
							'saleList': []
						}
					}
					$scope.viewMap[value.place_code].saleList.push(value);
				});
            } else {
                toaster.error({title: '', body: res.errmsg });
            }
        });
	}

	$scope.searchArea = function (code) {
        $resource('/api/us/sc/city/arealist', {}, {}).save({'code': code}, function(res) {
			if (res.errcode === 0) {
                if (code) {
                    $scope.searchParams.cityList = res.data;
                    $scope.searchParams.cityList.unshift({
                        name: '--- 全部 ---',
                        code: ''
                    });
                    $scope.searchParams.city = '';
                } else {
                    $scope.searchParams.provinceList = res.data;
                    $scope.searchParams.provinceList.unshift({
                        name: '--- 全部 ---',
                        code: ''
                    });
                    $scope.searchParams.province = '';
				}
            } else {
                toaster.error({title: '', body: '获取城市信息失败'});
            }
        });
    }
	
	init();
	//初始化页面参数
	function init(){
		$scope.searchParams = {};
		$scope.getList();
		$scope.searchArea();
	}

	//创建游团
	$scope.buy = function(sale){
        var modalInstance = $modal.open({
          template: require('../views/groupModel.html'),
          controller: 'groupModel',
          size: 'lg',
          resolve: {
			getDate : function(utilservice){
                return utilservice.getDate;
            },
			sale : function(){
                return sale;
            },
            updateFlag : function(){
                return false;
            }
          }
        });
        modalInstance.result.then(function () {
            var modalInstance1 = $modal.open({
                template: require('../views/tempSkip.html'),
                controller: 'tempSkip',
                size: 'lg'
            });
        });
    };

	//景区介绍
	$scope.introduce = function(place_code){
        var modalInstance = $modal.open({
          template: require('../views/placeDetail.html'),
          controller: 'placeDetail',
          size: 'lg',
          resolve: {
			place_code : function(){
                return place_code;
            }
          }
        });
    };

    //查看图片
    $scope.lookImg = function (url) {
        var modalInstance = $modal.open({
            template: require('../views/img.html'),
            controller: 'img',
            size: 'lg',
            resolve: {
                img: function () {
                    return url;
                }
            }
        });
        modalInstance.result.then(function (result) {
        });
    }


};